// 基础错误类
export class BaseError extends Error {
  public statusCode: number
  public errorCode: string

  constructor(message: string, statusCode: number = 500, errorCode: string = 'INTERNAL_ERROR') {
    super(message)
    this.name = this.constructor.name
    this.statusCode = statusCode
    this.errorCode = errorCode
    Error.captureStackTrace(this, this.constructor)
  }
}

// 参数错误 - 400
export class ParameterError extends BaseError {
  constructor(message: string = 'Invalid parameters') {
    super(message, 400, 'PARAMETER_ERROR')
  }
}

// 未授权错误 - 401
export class UnauthorizedError extends BaseError {
  constructor(message: string = 'Unauthorized') {
    super(message, 401, 'UNAUTHORIZED')
  }
}

// 禁止访问错误 - 403
export class ForbiddenError extends BaseError {
  constructor(message: string = 'Forbidden') {
    super(message, 403, 'FORBIDDEN')
  }
}

// 资源不存在错误 - 404
export class NotFoundError extends BaseError {
  constructor(message: string = 'Resource not found') {
    super(message, 404, 'NOT_FOUND')
  }
}

// 冲突错误 - 409
export class ConflictError extends BaseError {
  constructor(message: string = 'Resource conflict') {
    super(message, 409, 'CONFLICT')
  }
}

// 验证错误 - 422
export class ValidationError extends BaseError {
  constructor(message: string = 'Validation failed') {
    super(message, 422, 'VALIDATION_ERROR')
  }
}

// 业务逻辑错误 - 400
export class BusinessError extends BaseError {
  constructor(message: string = 'Business logic error') {
    super(message, 400, 'BUSINESS_ERROR')
  }
}
